﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SnippetCreator
{
    public partial class LiteralForm : Form
    {
        Snippet _snippet;
        public LiteralForm(string literalText, Snippet snippet, SnippetLiteral literal)
        {
            InitializeComponent();
            literalBindingSource.DataSource = literal;
            _snippet = snippet;
            literalLabel.Text = literalText;
        }

        private void okButton_Click(object sender, EventArgs e)
        {

        }

        private void idTextBox_Validating(object sender, CancelEventArgs e)
        {
            if (String.IsNullOrEmpty(idTextBox.Text))
            {
                validError.SetError(idTextBox, "Literal ID cannot be empty. Please, enter some value.");
                e.Cancel = true;
                return;
            }
            else
            {
                SnippetLiteral thisLiteral = literalBindingSource.DataSource as SnippetLiteral;
                foreach (SnippetLiteral sl in _snippet.Literals)
                {
                    if (sl != thisLiteral && sl.ID == idTextBox.Text)
                    {
                        validError.SetError(idTextBox, "Literal with this ID exists. Please, enter another.");
                        e.Cancel = true;
                        return;
                    }
                }
            }
            validError.Clear();
        }

        private void defaultTextBox_Validating(object sender, CancelEventArgs e)
        {
            if (String.IsNullOrEmpty(defaultTextBox.Text))
            {
                validError.SetError(defaultTextBox, "Literal default value cannot be empty. Please, enter some value.");
                e.Cancel = true;
                return;
            }
            validError.Clear();
        }

    }
}
